#pragma once

/*
 * Functions to operate on files, using native functions where needed
 * Dependencies: bzbutil
 */


#include <string>
#include <vector>
#include <cstdint>


namespace bzbfile {


/*
 * Extracts the path to a file given its path
 */

std::string path(const std::string &path);


/*
 * Extracts a file's extension given its full filename or path
 */

std::string extension(const std::string& filename);


/*
 * Extracts a file's name given its full filename or path
 */

std::string name(const std::string &filename);


/*
 * Extracts a file's base name given its full filename or path
 */

std::string basename(const std::string &filename);


/*
 * Checks if a file with the given name exists
 */

bool exists(const std::string &filename);


/*
 * Checks if a folder with the given name exists
 */

bool exists_dir(const std::string &dir);


/*
 * Returns the file of the specified file
 */

int64_t size(const std::string &filename);


/*
 * Returns the path pointed to by the given symlink
 */

std::string readlink(const std::string &symlink);


/*
 * Removes the specified file
 */

void remove(const std::string &filename);


/*
 * Removes recursively a directory and all its files and folders
 */

void remove_dir(const std::string &dir);


/*
 * Reads a text file and returns the data inside a string
 */

std::string read(const std::string &filename);


/*
 * Reads a binary file and returns the data inside a vector
 * Returns true on success, false otherwise
 * You can specify how many bytes to read and from which offset
 * Default size is 0, to read all file's content.
 */

std::vector<char> read_bin(const std::string &filename, uint64_t size = 0, uint64_t offset = 0);


/*
 * Writes a string to a file
 */

void write(	const std::string &filename,
			const std::string &data,
			bool truncate = true);


/*
 * Writes binary data to a file
 * Returns the count of written bytes
 */

size_t write_bin(const std::string &filename,
				 const std::vector<char> &data,
				 bool truncate = true);

/*
 * Writes binary data to a file of the specified size
 * starting from the offset
 * Returns the count of written bytes
 */

size_t write_bin(const std::string &filename,
                 uint64_t offset,
				 const std::vector<char> &data);


/*
 * Returns a list of the files inside the given directory
 */

std::vector<std::string> get_dir_file_list(const std::string &dir);


/*
 * Returns a list of the folders inside the given directory
 */

std::vector<std::string> get_dir_folder_list(const std::string &dir);


/*
 * Returns the path to the current executable
 */
std::string get_exe_path();


}
